package com.zj.web.controller;

import com.zj.service.ProductService;
import com.zj.web.bean.ProductDTO;
import com.zj.web.bean.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/auth/product")
@RefreshScope //开启动态刷新
@Tag(name = "商品控制器",description = "提供对商品资源的添加，查询并显示等操作")
public class AuthProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("/special/{productStatus}")
    @Operation(summary = "查询特价商品",description = "查询特价商品")
    public ResponseEntity<ResponseResult> specialProducts(@PathVariable("productStatus") Integer productStatus){
        List<ProductDTO> products = productService.getSpecialProducts(productStatus);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(products).build());
    }

    @GetMapping("/all/{productStatus}")
    @Operation(summary = "根据状态查询所有商品",description = "根据商品状态查询所有商品")
    public ResponseEntity<ResponseResult> allProducts(@PathVariable("productStatus") Integer productStatus){
        List<ProductDTO> products = productService.getAllProducts(productStatus);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(products).build());
    }

    @GetMapping("/{productId}")
    @Operation(summary = "根据ID查询商品",description = "根据商品ID查询商品")
    public ResponseEntity<ResponseResult> getProductById(@PathVariable("productId") Long productId){
        ProductDTO product = productService.getProductById(productId);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(product).build());
    }

    @GetMapping("/category/{categoryId}")
    @Operation(summary = "根据分类ID查询商品",description = "根据分类ID查询商品")
    public ResponseEntity<ResponseResult> getProductsByCategoryId(@PathVariable("categoryId") Long categoryId){
        List<ProductDTO> products = productService.getProductsByCategoryId(categoryId);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(products).build());
    }

    //根据产品id连接查询+类别表 查询全部信息
    @GetMapping("/detail/{productId}")
    @Operation(summary = "根据产品ID查询商品详情",description = "根据产品ID查询商品详情")
    public ResponseEntity<ResponseResult> getProductDetailById(@PathVariable("productId") Long productId){
        ProductDTO productDTO = productService.getProductDetailById(productId);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(productDTO).build());
    }

    //根据产品名字查询
    @GetMapping("/name/{productName}")
    @Operation(summary = "根据产品名字查询商品",description = "根据产品名字查询商品")
    public ResponseEntity<ResponseResult> getProductsByName(@PathVariable("productName") String productName){
        ProductDTO productDTO = productService.getProductsByName(productName);
        return ResponseEntity.ok(ResponseResult.builder().code(1).msg("查询成功").data(productDTO).build());
    }
}
